package org.jeecg.modules.demo3.fly.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author wjn
 * @version V1.0
 * @date 2021/9/18 15:20
 * @Copyright © 2021/9/18 深圳卓翼航空无人机有限公司
 */
@Component
public class BeanContext implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            this.applicationContext = applicationContext;
    }

    public ApplicationContext getApplicationContext(){
        return applicationContext;
    }

    @SuppressWarnings("uncheckes")
    public static <T> T getBean(String name) throws BeansException{
        return (T)applicationContext.getBean(name);
    }

    public static <T> T getBean(Class<T> clz) throws BeansException{
        return (T)applicationContext.getBean(clz);
    }
}
